package com.ran.contentproviderdemo;

import android.content.ContentValues;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import com.ran.providermodule.provider.ProviderDao;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.*;

/**
 * Instrumentation test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    Context appContext = InstrumentationRegistry.getTargetContext();

    @Test
    public void useAppContext() throws Exception {
        // Context of the app under test.

        assertEquals("com.ran.contentproviderdemo", appContext.getPackageName());
    }

    @Test
    public void query() throws Exception {
        ProviderDao.getInstance(appContext).query();
    }

    @Test
    public void insert() throws Exception {
        ContentValues contentValues = new ContentValues();
        contentValues.put("title", "ranqiliang");
        contentValues.put("name", "ranqiliang");
        contentValues.put("date_added", "20171021");
        contentValues.put("SEX", "man");
        ProviderDao.getInstance(appContext).insert(contentValues);
    }

    @Test
    public void batchInsert() throws Exception {
        List<ContentValues> contentValuesList = new ArrayList<>();
        for (int i = 0; i < 3000; i++) {
            ContentValues contentValues = new ContentValues();
            contentValues.put("title", "ranqiliang");
            contentValues.put("name", "ranqiliang");
            contentValues.put("date_added", "20171021");
            contentValues.put("SEX", "man");
            contentValuesList.add(contentValues);
        }
        ProviderDao.getInstance(appContext).batchInsert(contentValuesList);
    }
}
